#
# Utils Python Makefile
# - In charge of building the utils as library, as well as smoke building the examples.
#
#
# params
CC=gcc
CXX=g++
GDIR=../../../
EXTRADEFS=-DLINUX_OS $(CE)
INCLUDES=-I$(GDIR)/utils
WFLAGSC=-Wall
WFLAGSCPP=-Wall
WFLAGSDCPP=
CFLAGS=-O0 -g3 -fPIC $(WFLAGSC) $(INCLUDES) $(EXTRADEFS)
CPPFLAGS=-O0 -g3 -fPIC $(WFLAGSCPP) $(INCLUDES) $(EXTRADEFS)
DCPPFLAGS=-O0 -g3 -fPIC $(WFLAGSDCPP) $(INCLUDES) $(EXTRADEFS)
LD=g++
LDFLAGS=-L$(GDIR)/utils
LIBS=
VPATH=
INCLUDE_EXPORT=../include
PYLIB=`python-config --includes`

# Define COMPILE and LINK commands
COMPILEC=$(CC) $(CFLAGS) -c
COMPILECPP=$(CXX) $(CPPFLAGS) -c
COMPILEDCPP=$(CXX) $(DCPPFLAGS) -c
LINK=$(LD) $(LDFLAGS)


.PHONY: all

# Define targets
TARGETS=pyGIMutils

# All rule compiles all per default
all: $(TARGETS)

###############################################
PHONY: libGIMutils.a
libGIMutils.a:
	+(cd $(GDIR)/utils; make libGIMutils.a)
###############################################
####### Python wrap for utils  ##############
pyGIMutils: libGIMutils.a
	swig $(INCLUDES) -c++ -python -o gimutils_Python.cpp ../../gimutils.i
	$(COMPILECPP) $(PYLIB) gimutils_Python.cpp -o gimutils_Python.opp

	$(LINK) -shared -fPIC -o _gimutils.so \
	gimutils_Python.opp -lGIMutils 

.PHONY: clean
clean: 
	rm -f *.so gimutils_*
	(cd $(GDIR)/utils; make clean)
	@echo "     [CLEAN]"

##############################################
##############################################
